﻿using System;
using System.Collections.Generic;
using UILib;
using UnityEngine;
using XMainClient.UI.UICommon;
using XUtliPoolLib;

namespace XMainClient.UI
{
	// Token: 0x02001842 RID: 6210
	internal class XShowGetItemUIView : DlgBase<XShowGetItemUIView, XShowGetItemUIBehaviour>
	{
		// Token: 0x1700394B RID: 14667
		// (get) Token: 0x06010218 RID: 66072 RVA: 0x003DC430 File Offset: 0x003DA630
		public override string fileName
		{
			get
			{
				return "GameSystem/ShowGetItemDlg";
			}
		}

		// Token: 0x1700394C RID: 14668
		// (get) Token: 0x06010219 RID: 66073 RVA: 0x003DC448 File Offset: 0x003DA648
		public override bool autoload
		{
			get
			{
				return true;
			}
		}

		// Token: 0x1700394D RID: 14669
		// (get) Token: 0x0601021A RID: 66074 RVA: 0x003DC45C File Offset: 0x003DA65C
		public override bool needOnTop
		{
			get
			{
				return true;
			}
		}

		// Token: 0x1700394E RID: 14670
		// (get) Token: 0x0601021B RID: 66075 RVA: 0x003DC470 File Offset: 0x003DA670
		public override bool isHideChat
		{
			get
			{
				return false;
			}
		}

		// Token: 0x0601021C RID: 66076 RVA: 0x003DC483 File Offset: 0x003DA683
		protected override void OnHide()
		{
			XSingleton<XTimerMgr>.singleton.KillTimer(this.m_token);
			base.OnHide();
		}

		// Token: 0x0601021D RID: 66077 RVA: 0x003DC49E File Offset: 0x003DA69E
		protected override void OnUnload()
		{
			XSingleton<XTimerMgr>.singleton.KillTimer(this.m_token);
			base.OnUnload();
		}

		// Token: 0x0601021E RID: 66078 RVA: 0x003DC4BC File Offset: 0x003DA6BC
		protected override void Init()
		{
			base.Init();
			bool flag = this._doc == null;
			if (flag)
			{
				this._doc = XDocuments.GetSpecificDocument<XShowGetItemDocument>(XShowGetItemDocument.uuID);
			}
		}

		// Token: 0x0601021F RID: 66079 RVA: 0x000FEEFC File Offset: 0x000FD0FC
		protected override void OnShow()
		{
		}

		// Token: 0x06010220 RID: 66080 RVA: 0x003DC4F0 File Offset: 0x003DA6F0
		private void Print(List<XItem> _items, string tag)
		{
			for (int i = 0; i < _items.Count; i++)
			{
				XSingleton<XDebug>.singleton.AddGreenLog(XSingleton<XCommon>.singleton.StringCombine(tag, string.Concat(new object[]
				{
					" itemid:",
					_items[i].itemID,
					" cnt:",
					_items[i].itemCount
				})), null, null, null, null, null);
			}
		}

		// Token: 0x06010221 RID: 66081 RVA: 0x003DC574 File Offset: 0x003DA774
		public void ShowItems(List<XItem> _items, OnTweenFinishEventHandler _end)
		{
			bool flag = this._doc == null;
			if (flag)
			{
				this._doc = XDocuments.GetSpecificDocument<XShowGetItemDocument>(XShowGetItemDocument.uuID);
			}
			bool flag2 = XEquipCreateDocument.Doc.IsForbidGetItemUI || this._doc.IsForbidByLua;
			if (flag2)
			{
				this.SetVisible(false, true);
				XShowGetItemDocument.ItemUIQueue.Clear();
			}
			else
			{
				bool flag3 = !base.IsVisible();
				if (flag3)
				{
					this.SetVisibleWithAnimation(true, null);
				}
				this.isPlaying = true;
				this.mAnimEnd = _end;
				this.m_items = _items;
				base.uiBehaviour.m_ShowItemPool.ReturnAll(false);
				this.GridItems();
				base.uiBehaviour.m_tweenBg.ResetTween(true);
				base.uiBehaviour.m_tweenBg.PlayTween(true, -1f);
				XSingleton<XTimerMgr>.singleton.KillTimer(this.m_token);
				XSingleton<XDebug>.singleton.AddGreenLog(base.uiBehaviour.m_tweener.Duration.ToString(), null, null, null, null, null);
				this.m_token = XSingleton<XTimerMgr>.singleton.SetTimer(base.uiBehaviour.m_tweener.Duration, new XTimerMgr.ElapsedEventHandler(this.OnPlayEnd), base.uiBehaviour.m_tweenBg);
			}
		}

		// Token: 0x06010222 RID: 66082 RVA: 0x003DC6B8 File Offset: 0x003DA8B8
		public void OnPlayEnd(object o = null)
		{
			bool flag = o != null;
			if (flag)
			{
				IXUITweenTool tween = o as IXUITweenTool;
				this.isPlaying = false;
				bool flag2 = this.mAnimEnd != null;
				if (flag2)
				{
					XSingleton<XDebug>.singleton.AddLog("play end!", null, null, null, null, null, XDebugColor.XDebug_None);
					this.mAnimEnd(tween);
				}
			}
			XSingleton<XDebug>.singleton.AddGreenLog("the end event", null, null, null, null, null);
		}

		// Token: 0x06010223 RID: 66083 RVA: 0x003DC728 File Offset: 0x003DA928
		public void OnPlayEnd(IXUITweenTool tween)
		{
			this.isPlaying = false;
			bool flag = this.mAnimEnd != null;
			if (flag)
			{
				XSingleton<XDebug>.singleton.AddLog("play end!", null, null, null, null, null, XDebugColor.XDebug_None);
				this.mAnimEnd(tween);
			}
		}

		// Token: 0x06010224 RID: 66084 RVA: 0x003DC770 File Offset: 0x003DA970
		public void HandlePlayEnd()
		{
			bool flag = base.uiBehaviour != null && base.uiBehaviour.m_ShowItemPool != null;
			if (flag)
			{
				base.uiBehaviour.m_ShowItemPool.ReturnAll(false);
			}
		}

		// Token: 0x06010225 RID: 66085 RVA: 0x003DC7B4 File Offset: 0x003DA9B4
		private void GridItems()
		{
			int count = this.m_items.Count;
			Vector3 localPosition = new Vector3(200f, -12f, 0f);
			base.uiBehaviour.m_sprBgTip.spriteHeight = ((count > 5) ? 300 : 250);
			for (int i = 0; i < count; i++)
			{
				bool flag = count > 5;
				if (flag)
				{
					int num = (count % 2 == 0) ? (count / 2) : (count / 2 + 1);
					bool flag2 = i < num;
					if (flag2)
					{
						localPosition.x = 100f * ((float)i - (float)(num - 1) / 2f);
						localPosition.y = -120f;
					}
					else
					{
						localPosition.x = 100f * ((float)(i - num) - (float)(count - num - 1) / 2f);
						localPosition.y = -220f;
					}
				}
				else
				{
					localPosition.x = 100f * ((float)i - (float)(count - 1) / 2f);
					localPosition.y = -145f;
				}
				GameObject gameObject = base.uiBehaviour.m_ShowItemPool.FetchGameObject(false);
				gameObject.name = "item" + i;
				gameObject.transform.localPosition = localPosition;
				XSingleton<XItemDrawerMgr>.singleton.DrawItem(gameObject, this.m_items[i]);
			}
		}

		// Token: 0x04007322 RID: 29474
		private XShowGetItemDocument _doc = null;

		// Token: 0x04007323 RID: 29475
		private List<XItem> m_items = new List<XItem>();

		// Token: 0x04007324 RID: 29476
		private uint m_token = 0U;

		// Token: 0x04007325 RID: 29477
		private OnTweenFinishEventHandler mAnimEnd;

		// Token: 0x04007326 RID: 29478
		public bool isPlaying = false;
	}
}
